options(scipen = 999)


library(tidyverse)
library(ggthemes)
library(lubridate)
library(viridis)
library(arm)
library(lfe)
library(ggalt)
library(ggpubr)


city.data <- read.csv('Data/city_data_minimal.csv')
ois.min <- read.csv('Data/OIS_Dataset_Minimal.csv')
load("Data/lemas/2020/38651-0001-Data.rda")
lemas.2020 <- da38651.0001
rm('da38651.0001')
nibrs.counts <- read.csv('Data/other_data/offenderCount20102021.csv')
nibrs.counts.violent <- read.csv(file='Data/other_data/violentOffenderCount20102021.csv')
census.race.data <- read.csv('Data/other_data/placeLevelBlackPercent20092019.csv')
census.hispanic.race.data <- read.csv('Data/other_data/placeLevelHispanicPercent20092019.csv')
weapon.mapping <- read.csv('Data/other_data/weapon_mapping.csv')

city.data$first.year <- rep(NA,dim(city.data)[1])
city.data$last.year <- rep(NA,dim(city.data)[1])
for(i in 1:nrow(city.data)){
  if(grepl('-',city.data$Range.Provided.By.City[i])){
    city.data$first.year[i] <- unlist(strsplit(as.character(city.data$Range.Provided.By.City[i]),'-',fixed=TRUE))[1]
    city.data$last.year[i] <- unlist(strsplit(as.character(city.data$Range.Provided.By.City[i]),'-',fixed=TRUE))[2]
  }
}
city.data$totalYears <- ifelse(!is.na(city.data$first.year), as.numeric(city.data$last.year)-as.numeric(city.data$first.year)+1,0)

ois.min$Weapon.Category <- weapon.mapping$Weapon.Category[match(ois.min$Suspect.Weapon, weapon.mapping$Suspect.Weapon)]
ois.min$Detailed.Weapon.Category <- weapon.mapping$Detailed.Weapon.Category[match(ois.min$Suspect.Weapon, weapon.mapping$Suspect.Weapon)]

ois.min <- ois.min %>% filter(Hit != 'Miss')


##############################################
##############################################
##
##  Figure 6.1
##
##############################################
##############################################


pdf('FinalFigures/fig6-1.pdf',5,4)
ois.min %>%
  mutate(race=ifelse(Suspect.Race %in% c('White','Black','Hispanic',
                                         'Asian'),
                     Suspect.Race, ifelse(Suspect.Race=='',
                                          'Unreported', 'Other'))) %>%
  mutate(race = factor(race,
                       levels = c('White','Black','Hispanic',
                                  'Asian',
                                  'Other',
                                  'Unreported'))) %>%
  ggplot() +
  geom_histogram(aes(x=race,
                     fill=ifelse(race=='Unreported','Missing','Other')), stat='count') +
  scale_x_discrete(guide = guide_axis(angle = 45)) +
  xlab('Subject Race') + ylab('Total Subjects') +
  scale_fill_manual(name = "race", values=c("grey","black")) +
  theme_tufte() +
  theme(plot.caption = element_text(hjust = 0), 
        axis.line = element_line(color = 'black')) +
  labs(title='Racial Composition of Police Shooting Subjects') +
  theme(legend.position = 'none') +
  #  scale_x_discrete(expand = c(0,0)) +
  scale_y_continuous(expand = c(0,0))
dev.off()



##############################################
##############################################
##
##  Figure 6.2
##
##############################################
##############################################


pdf('FinalFigures/fig6-2a.pdf',5,5)
ois.min %>%
  filter(Suspect.Race != '') %>%
  left_join(city.data %>% dplyr::select(LEAR_ID,GEOID)) %>%
  group_by(GEOID,Year) %>%
  summarize(n=n(),
            black.shot = sum(Suspect.Race=='Black', na.rm=TRUE),
            white.shot = sum(Suspect.Race=='White', na.rm=TRUE),
            black.sus.ratio = mean(black.shot/n, na.rm=TRUE)) %>%
  left_join(census.race.data %>% 
              dplyr::select(GEOID,year,percent.black), by=c('GEOID' = 'GEOID', 'Year' = 'year')) %>%
  ggplot() +
  geom_smooth(aes(x=percent.black, y=black.sus.ratio), color='black') +
  geom_point(aes(x=percent.black, y=black.sus.ratio, size=n), alpha=.5) +
  theme_tufte() +
  labs(
    y='% of Subjects Who Are Black',
    x='% of the Population Who Are Black') +
  theme(plot.caption = element_text(hjust = 0)) +
  ylim(0,1) +
  labs(size='Shootings') + xlim (0,1) +
  geom_abline(intercept=0)  +
  scale_y_continuous(expand=c(0,0), limits=c(-50,100)) +
  coord_cartesian(ylim=c(-.01,1.01)) + 
  geom_abline(intercept=0)  +
  scale_y_continuous(expand=c(0,0), limits=c(-50,100)) +
  coord_cartesian(ylim=c(-.01,1.01)) + 
  theme(axis.title.x = element_text(size = 20), 
        axis.title.y = element_text(size = 20),
        axis.line=element_line()) +
  theme(legend.position = 'none')
dev.off()




pdf('FinalFigures/fig6-2b.pdf',5,5)
ois.min %>%
  filter(Suspect.Race != '') %>%
  left_join(city.data %>% dplyr::select(LEAR_ID,ORI9)) %>%
  group_by(ORI9,Year) %>%
  summarize(n=n(),
            black.shot = sum(Suspect.Race=='Black', na.rm=TRUE),
            white.shot = sum(Suspect.Race=='White', na.rm=TRUE),
            black.sus.ratio = mean(black.shot/n, na.rm=TRUE)) %>%
  left_join(nibrs.counts %>%
              group_by(year,ori) %>%
              summarise(offenders = sum(offs)), by=c('Year' = 'year', 'ORI9' = 'ori')) %>%
  left_join(nibrs.counts %>%
              filter(race_of_offender == 'black') %>%
              group_by(year,ori) %>%
              summarise(black.offenders = sum(offs)), by=c('Year' = 'year', 'ORI9' = 'ori')) %>%
  mutate(perc.black.offenders = black.offenders/offenders) %>%
  ggplot() +
  geom_smooth(aes(x=perc.black.offenders, y=black.sus.ratio), color='black') +
  geom_point(aes(x=perc.black.offenders, y=black.sus.ratio, size=n), alpha=.5) +
  theme_tufte() +
  labs(
    y='% of Subjects Who Are Black',
    x='% of Offenders Who Are Black') +
  theme(plot.caption = element_text(hjust = 0)) +
  ylim(0,1) +
  labs(size='Shootings') + xlim (0,1) +
  geom_abline(intercept=0)  +
  scale_y_continuous(expand=c(0,0), limits=c(-50,100)) +
  coord_cartesian(ylim=c(-.01,1.01)) + 
  geom_abline(intercept=0)  +
  scale_y_continuous(expand=c(0,0), limits=c(-50,100)) +
  coord_cartesian(ylim=c(-.01,1.01)) + 
  theme(axis.title.x = element_text(size = 20), 
        axis.title.y = element_text(size = 20),
        axis.line=element_line()) +
  theme(legend.position = 'none')
dev.off()


pdf('FinalFigures/fig6-2c.pdf',5,5)
ois.min %>%
  filter(Suspect.Race != '') %>%
  left_join(city.data %>% dplyr::select(LEAR_ID,ORI9)) %>%
  group_by(ORI9,Year) %>%
  summarize(n=n(),
            black.shot = sum(Suspect.Race=='Black', na.rm=TRUE),
            white.shot = sum(Suspect.Race=='White', na.rm=TRUE),
            black.sus.ratio = mean(black.shot/n, na.rm=TRUE)) %>%
  left_join(nibrs.counts.violent %>%
              group_by(year,ori) %>%
              summarise(offenders = sum(offs)), by=c('Year' = 'year', 'ORI9' = 'ori')) %>%
  left_join(nibrs.counts.violent %>%
              filter(race_of_offender == 'black') %>%
              group_by(year,ori) %>%
              summarise(black.offenders = sum(offs)), by=c('Year' = 'year', 'ORI9' = 'ori')) %>%
  mutate(perc.black.offenders = black.offenders/offenders) %>%
  ggplot() +
  geom_smooth(aes(x=perc.black.offenders, y=black.sus.ratio), color='black') +
  geom_point(aes(x=perc.black.offenders, y=black.sus.ratio, size=n), alpha=.5) +
  theme_tufte() +
  labs(
    y='% of Subjects Who Are Black',
    x='% of Violent Offenders Who Are Black') +
  theme(plot.caption = element_text(hjust = 0)) +
  ylim(0,1) +
  labs(size='Shootings') + xlim (0,1) +
  geom_abline(intercept=0)  +
  scale_y_continuous(expand=c(0,0), limits=c(-50,100)) +
  coord_cartesian(ylim=c(-.01,1.01)) + 
  geom_abline(intercept=0)  +
  scale_y_continuous(expand=c(0,0), limits=c(-50,100)) +
  coord_cartesian(ylim=c(-.01,1.01)) + 
  theme(axis.title.x = element_text(size = 20), 
        axis.title.y = element_text(size = 20),
        axis.line=element_line()) +
  theme(legend.position = 'none')
dev.off()



##############################################
##############################################
##
##  Figure 6.3
##
##############################################
##############################################


pdf('FinalFigures/fig6-3a.pdf',5,5)
ois.min %>%
  filter(Suspect.Race != '') %>%
  left_join(city.data %>% dplyr::select(LEAR_ID,GEOID)) %>%
  group_by(GEOID,Year) %>%
  summarize(n=n(),
            hispanic.shot = sum(Suspect.Race=='Hispanic', na.rm=TRUE),
            white.shot = sum(Suspect.Race=='White', na.rm=TRUE),
            hispanic.sus.ratio = mean(hispanic.shot/n, na.rm=TRUE)) %>%
  left_join(census.hispanic.race.data %>% 
              dplyr::select(GEOID,year,percent.hispanic), by=c('GEOID' = 'GEOID', 'Year' = 'year')) %>%
  ggplot() +
  geom_smooth(aes(x=percent.hispanic, y=hispanic.sus.ratio), color='black') +
  geom_point(aes(x=percent.hispanic, y=hispanic.sus.ratio, size=n), alpha=.5) +
  labs(y='% of Subjects Who Are Hispanic',
       x='% of the Population Who Are Hispanic') +
  theme_tufte() +
  theme(axis.title.x = element_text(size = 20), 
        axis.title.y = element_text(size = 20),
        axis.line=element_line()) +
  theme(plot.caption = element_text(hjust = 0)) +
  ylim(0,1) +
  labs(size='Shootings') + xlim (0,1) +
  geom_abline(intercept=0)  +
  scale_y_continuous(expand=c(0,0), limits=c(-50,100)) +
  coord_cartesian(ylim=c(-.01,1.01)) + 
  geom_abline(intercept=0)  +
  scale_y_continuous(expand=c(0,0), limits=c(-50,100)) +
  coord_cartesian(ylim=c(-.01,1.01)) + 
  theme(legend.position = 'none')
dev.off()


pdf('FinalFigures/fig6-3b.pdf',5,5)
ois.min %>%
  filter(Suspect.Race != '') %>%
  left_join(city.data %>% dplyr::select(LEAR_ID,ORI9)) %>%
  group_by(ORI9,Year) %>%
  summarize(n=n(),
            hispanic.shot = sum(Suspect.Race=='Hispanic', na.rm=TRUE),
            white.shot = sum(Suspect.Race=='White', na.rm=TRUE),
            hispanic.sus.ratio = mean(hispanic.shot/n, na.rm=TRUE)) %>%
  left_join(nibrs.counts %>%
              group_by(year,ori) %>%
              summarise(offenders = sum(offs)), by=c('Year' = 'year', 'ORI9' = 'ori')) %>%
  left_join(nibrs.counts %>%
              filter(ethnicity_of_offender == 'hispanic origin') %>%
              group_by(year,ori) %>%
              summarise(hispanic.offenders = sum(offs)), by=c('Year' = 'year', 'ORI9' = 'ori')) %>%
  mutate(perc.hispanic.offenders = hispanic.offenders/offenders) %>%
  ggplot() +
  geom_smooth(aes(x=perc.hispanic.offenders, y=hispanic.sus.ratio), color='black') +
  geom_point(aes(x=perc.hispanic.offenders, y=hispanic.sus.ratio, size=n), alpha=.5) +
  theme_tufte() +
  theme(axis.title.x = element_text(size = 20), 
        axis.title.y = element_text(size = 20),
        axis.line=element_line()) +
  labs(y='% of Subjects Who Are Hispanic',
       x='% of Offenders Who Are Hispanic') +
  theme(plot.caption = element_text(hjust = 0)) +
  ylim(0,1) +
  labs(size='Shootings') + xlim (0,1) +
  geom_abline(intercept=0)  +
  scale_y_continuous(expand=c(0,0), limits=c(-50,100)) +
  coord_cartesian(ylim=c(-.01,1.01)) + 
  geom_abline(intercept=0)  +
  scale_y_continuous(expand=c(0,0), limits=c(-50,100)) +
  coord_cartesian(ylim=c(-.01,1.01)) + 
  theme(legend.position = 'none')
dev.off()


pdf('FinalFigures/fig6-3c.pdf',5,5)
ois.min %>%
  filter(Suspect.Race != '') %>%
  left_join(city.data %>% dplyr::select(LEAR_ID,ORI9)) %>%
  group_by(ORI9,Year) %>%
  summarize(n=n(),
            hispanic.shot = sum(Suspect.Race=='Hispanic', na.rm=TRUE),
            white.shot = sum(Suspect.Race=='White', na.rm=TRUE),
            hispanic.sus.ratio = mean(hispanic.shot/n, na.rm=TRUE)) %>%
  left_join(nibrs.counts.violent %>%
              group_by(year,ori) %>%
              summarise(offenders = sum(offs)), by=c('Year' = 'year', 'ORI9' = 'ori')) %>%
  left_join(nibrs.counts.violent %>%
              filter(ethnicity_of_offender == 'hispanic origin') %>%
              group_by(year,ori) %>%
              summarise(hispanic.offenders = sum(offs)), by=c('Year' = 'year', 'ORI9' = 'ori')) %>%
  mutate(perc.hispanic.offenders = hispanic.offenders/offenders) %>%
  ggplot() +
  geom_smooth(aes(x=perc.hispanic.offenders, y=hispanic.sus.ratio), color='black') +
  geom_point(aes(x=perc.hispanic.offenders, y=hispanic.sus.ratio, size=n), alpha=.5) +
  theme_tufte() +
  theme(axis.title.x = element_text(size = 20), 
        axis.title.y = element_text(size = 20),
        axis.line=element_line()) +
  theme(plot.caption = element_text(hjust = 0)) +  
  labs(y='% of Subjects Who Are Hispanic',
       x='% of Violent Offenders Who Are Hispanic') +
  theme(plot.caption = element_text(hjust = 0)) +
  ylim(0,1) +
  labs(size='Shootings') + xlim (0,1) +
  geom_abline(intercept=0)  +
  scale_y_continuous(expand=c(0,0), limits=c(-50,100)) +
  coord_cartesian(ylim=c(-.01,1.01)) + 
  geom_abline(intercept=0)  +
  scale_y_continuous(expand=c(0,0), limits=c(-50,100)) +
  coord_cartesian(ylim=c(-.01,1.01)) + 
  theme(legend.position = 'none')
dev.off()






########################################
########################################
##
##    Figure 6.4
##
########################################

pdf('FinalFigures/fig6-4.pdf',5,4)
ois.min %>%
  mutate(race=ifelse(Officer.Race %in% c('White','Black','Hispanic',
                                         'Asian'),
                     Officer.Race, ifelse(Officer.Race=='',
                                          'Unreported', 'Other'))) %>%
  mutate(race = factor(race,
                       levels = c('White','Black','Hispanic',
                                  'Asian',
                                  'Other',
                                  'Unreported'))) %>%
  ggplot() +
  geom_histogram(aes(x=race,
                     fill=factor(ifelse(race=='Unreported','Grey','Normal'))), stat='count') +
  scale_x_discrete(guide = guide_axis(angle = 45)) +
  scale_fill_manual(name = "race", values=c("grey","black")) +
  xlab('Officer Race') + ylab('Total') +
  theme_tufte() +
  theme(plot.caption = element_text(hjust = 0), 
        axis.line = element_line(color = 'black')) +
  labs(title='Racial Composition of Officers',
       x='Officer Race',y='Total Police Shootings') +
  theme(legend.position = 'none')+
  #  scale_x_discrete(expand = c(0,0)) +
  scale_y_continuous(expand = c(0,0))

dev.off()


########################################
########################################
##
##    Figure 6.5
##
########################################
all.ages <- ois.min %>%
  mutate(age=as.numeric(Suspect.Age)) %>%
  filter(age<100) %>%     # deal with 4 observations from Seattle with excel error
  filter(age>17) %>%     # get rid of any minors
  ggplot() +
  geom_histogram(aes(x=age)) +
  theme_tufte() +
  labs(title='Distribution of Age of Subjects Shot by Police',
       subtitle = 'All Subjects',
       x='Age',y='Total Subjects') +
  theme(plot.caption = element_text(hjust = 0), 
        axis.line = element_line(color = 'black')) +
  scale_x_continuous(expand = c(0,0)) +
  scale_y_continuous(expand = c(0,0)) +
  xlim(18,90)

white <- ois.min %>%
  mutate(age=as.numeric(Suspect.Age)) %>%
  filter(age<100) %>%     # deal with 4 observations from Seattle with excel error
  filter(age>17) %>%     # get rid of any minors
  filter(Suspect.Race=='White') %>%
  ggplot() +
  geom_histogram(aes(x=age)) +
  theme_tufte() +
  labs(subtitle='White Subjects Only',
       x='Age',y='Total Subjects') +
  theme(plot.caption = element_text(hjust = 0), 
        axis.line = element_line(color = 'black')) +
  scale_x_continuous(expand = c(0,0)) +
  scale_y_continuous(expand = c(0,0)) +
  xlim(18,90)

black <- ois.min %>%
  mutate(age=as.numeric(Suspect.Age)) %>%
  filter(age<100) %>%     # deal with 4 observations from Seattle with excel error
  filter(age>17) %>%     # get rid of any minors
  filter(Suspect.Race=='Black') %>%
  ggplot() +
  geom_histogram(aes(x=age)) +
  theme_tufte() +
  labs(subtitle='Black Subjects Only',
       x='Age',y='Total Subjects') +
  theme(plot.caption = element_text(hjust = 0), 
        axis.line = element_line(color = 'black')) +
  scale_x_continuous(expand = c(0,0)) +
  scale_y_continuous(expand = c(0,0)) +
  xlim(18,90)

hispanic <- ois.min %>%
  mutate(age=as.numeric(Suspect.Age)) %>%
  filter(age<100) %>%     # deal with 4 observations from Seattle with excel error
  filter(age>17) %>%     # get rid of any minors
  filter(Suspect.Race=='Hispanic') %>%
  ggplot() +
  geom_histogram(aes(x=age)) +
  theme_tufte() +
  labs(subtitle='Hispanic Subjects Only',
       x='Age',y='Total Subjects') +
  theme(plot.caption = element_text(hjust = 0), 
        axis.line = element_line(color = 'black')) +
  scale_x_continuous(expand = c(0,0)) +
  scale_y_continuous(expand = c(0,0)) +
  xlim(18,90)


pdf('FinalFigures/fig6-5.pdf',8,6)
ggarrange(all.ages,                                                 # First row with scatter plot
          ggarrange(white,black,hispanic, ncol = 3), # Second row with box and dot plots
          nrow = 2                                        # Labels of the scatter plot
          
) 
dev.off()




##############################################
##############################################
##
##  Figure 6.6
##
##############################################
##############################################

pdf('FinalFigures/fig6-6.pdf',5,4)
ois.min %>%
  mutate(Weapon.Category = ifelse(Weapon.Category=='',NA, Weapon.Category)) %>%
  mutate(Weapon.Category = ifelse(is.na(Weapon.Category),'Missing',Weapon.Category)) %>%
  mutate(Weapon.fac =
           factor(Weapon.Category,
                  levels=c('Gun','Unarmed','Sharp','Other',
                           'Vehicle','Unknown','Blunt','Multiple',
                           'Explosives','Missing'))) %>%
  ggplot() +
  geom_histogram(aes(x=Weapon.fac,
                     fill=ifelse(Weapon.fac=='Missing','Missing','Other')), stat='count') +
  scale_fill_manual(name = "race", values=c("grey","black")) +
  theme_tufte() +
  theme(plot.caption = element_text(hjust = 0), 
        axis.line = element_line(color = 'black')) +
  theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1),
        legend.position = 'none') +
  labs(title='Distribution of Weapons Used by Subjects',
       x='Suspect Weapon',
       y='Total Police Shootings') +
  scale_x_discrete(expand = c(0,0)) +
  scale_y_continuous(expand = c(0,0)) 
dev.off()  


##############################################
##############################################
##
##  Figure 6.7
##
##############################################
##############################################



all.age.armed <- ois.min %>%
  mutate(armed = ifelse(Weapon.Category=='Unarmed','Unarmed','Armed')) %>%
  mutate(age = as.numeric(Suspect.Age),
         armed.num=ifelse(armed=='Armed',1,ifelse(armed=='Unarmed',0,NA))) %>%
  filter(age<95) %>%
  ggplot() + 
  geom_point(aes(x=jitter(age),y=armed.num)) +
  geom_smooth(aes(x=age,y=armed.num),method="glm", 
              method.args = list(family = "binomial"), color='black') +
  scale_y_continuous(expand=c(0,0), limits=c(-50,100)) +
  coord_cartesian(ylim=c(-.01,1.01)) +
  theme_tufte() +
  theme(plot.caption = element_text(hjust = 0), 
        axis.line = element_line(color = 'black')) +
  labs(title = 'Suspect Ages and Whether They Are Armed',
       x='Age',y='% Armed') +
  theme(plot.caption = element_text(hjust = 0)) +
  xlim(18,90)

pdf('FinalFigures/fig6-7.pdf',5,4)
all.age.armed
dev.off()



##############################################
##############################################
##
##  Figure 6.8
##
##############################################
##############################################
white.age.armed <- ois.min %>%
  mutate(armed = ifelse(Weapon.Category=='Unarmed','Unarmed','Armed')) %>%
  mutate(age = as.numeric(Suspect.Age),
         armed.num=ifelse(armed=='Armed',1,ifelse(armed=='Unarmed',0,NA))) %>%
  filter(age<95) %>%
  filter(Suspect.Race=='White') %>%
  ggplot() + 
  geom_point(aes(x=jitter(age),y=armed.num)) +
  geom_smooth(aes(x=age,y=armed.num),method="glm", 
              method.args = list(family = "binomial"), color='black') +
  scale_y_continuous(expand=c(0,0), limits=c(-50,100)) +
  coord_cartesian(ylim=c(-.01,1.01)) +
  theme_tufte() +
  theme(plot.caption = element_text(hjust = 0), 
        axis.line = element_line(color = 'black')) +
  labs(title='White Subjects and Whether They Are Armed',
       x='Age',y='% Armed') +
  theme(plot.caption = element_text(hjust = 0)) +
  xlim(18,90) +
  theme(plot.caption = element_text(hjust = 0), 
        axis.line = element_line(color = 'black'))

black.age.armed <- ois.min %>%
  mutate(armed = ifelse(Weapon.Category=='Unarmed','Unarmed','Armed')) %>%
  mutate(age = as.numeric(Suspect.Age),
         armed.num=ifelse(armed=='Armed',1,ifelse(armed=='Unarmed',0,NA))) %>%
  filter(age<95) %>%
  filter(Suspect.Race=='Black') %>%
  ggplot() + 
  geom_point(aes(x=jitter(age),y=armed.num)) +
  geom_smooth(aes(x=age,y=armed.num),method="glm", 
              method.args = list(family = "binomial"), color='black') +
  scale_y_continuous(expand=c(0,0), limits=c(-50,100)) +
  coord_cartesian(ylim=c(-.01,1.01)) +
  theme_tufte() +
  theme(plot.caption = element_text(hjust = 0), 
        axis.line = element_line(color = 'black')) +
  labs(title='Black Subjects and Whether They Are Armed',
       x='Age',y='% Armed') +  
  theme(plot.caption = element_text(hjust = 0)) +
  xlim(18,90) 

hispanic.age.armed <- ois.min %>%
  mutate(armed = ifelse(Weapon.Category=='Unarmed','Unarmed','Armed')) %>%
  mutate(age = as.numeric(Suspect.Age),
         armed.num=ifelse(armed=='Armed',1,ifelse(armed=='Unarmed',0,NA))) %>%
  filter(age<95) %>%
  filter(Suspect.Race=='Hispanic') %>%
  ggplot() + 
  geom_point(aes(x=jitter(age),y=armed.num)) +
  geom_smooth(aes(x=age,y=armed.num),method="glm", 
              method.args = list(family = "binomial"), color='black') +
  scale_y_continuous(expand=c(0,0), limits=c(-50,100)) +
  coord_cartesian(ylim=c(-.01,1.01)) +
  theme_tufte() +
  theme(plot.caption = element_text(hjust = 0), 
        axis.line = element_line(color = 'black')) +
  labs(title='Hispanic Subjects and Whether They Are Armed',
       x='Age',y='% Armed') +
  theme(plot.caption = element_text(hjust = 0)) +
  xlim(18,90)  

pdf('FinalFigures/fig6-8a.pdf',5,4)
white.age.armed
dev.off()

pdf('FinalFigures/fig6-8b.pdf',5,4)
black.age.armed
dev.off()

pdf('FinalFigures/fig6-8c.pdf',5,4)
hispanic.age.armed
dev.off()
